﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using XinGuanERP.Attributes.system;
using XinGuanERP.Models.Vo.business;
using XinGuanERP.Services.business.IServices;
using XinGuanERP.Utils;

namespace XinGuanERP.Controllers.business;

[DynamicApiController]
public class ProductController
{
    private readonly IProductService _productService;

    public ProductController(IProductService productService)
    {
        _productService = productService;
    }

    [Authorize]
    [ServiceFilter(typeof(MyActionFilterAttribute))]
    public ResultUtil AddProduct(ProductVo productVo) =>
        ResultUtil.ok(_productService.AddProduct(productVo));

    [Authorize]
    [ServiceFilter(typeof(MyActionFilterAttribute))]
    public ResultUtil UpdateProduct(ProductVo productVo) =>
        ResultUtil.ok(_productService.UpdateProduct(productVo));

    [Authorize]
    [ServiceFilter(typeof(MyActionFilterAttribute))]
    public ResultUtil DeleteProduct(string id) =>
        ResultUtil.ok(_productService.DeleteProduct(id));

    [Authorize]
    [ServiceFilter(typeof(MyActionFilterAttribute))]
    [HttpPost]
    public ResultUtil GetProductWithPage(ProductVo productVo) =>
        ResultUtil.ok(_productService.GetProductWithPage(productVo));
    
    [Authorize]
    [ServiceFilter(typeof(MyActionFilterAttribute))]
    public ResultUtil GetProductWithList() =>
        ResultUtil.ok(_productService.GetProductWithList());
}